<?php
namespace app\manage\controller;
use app\manage\controller\BaseController;
use think\facade\Db;
use think\facade\View;
use app\model\Message as Messagemodel;
class Message extends BaseController
{
    public function index()
    {
    	$link=new Messagemodel();
		$key=input('key','');
        View::assign('key',$key);
        $link=$link->whereor('title','like','%'.$key.'%')
                        ->order('id desc')
                        ->paginate(10,false,['query'=>request()->param()]);
        View::assign('comment',$link);
        View::assign('count1',$link->total());
       	return View::fetch();
    }
	public function ajax()
    {
    	$data=input('post.');
		$message=new Messagemodel();
		if($data['type']=='member_del'){
			$id=$data['id'];
			$info=$message->destroy($id);
			$liu=$message->where('isopen','0')->count();
			if($info){
				return json([1,$liu]);
			}else{
				return 0;
			}
		}
		return 0;
    }
	public function edit()
    {
    	$message=new Messagemodel();
    	if(request()->isPost()){
    		$data=input('post.');
			$res=$message->update($data,['id' => input('id')]);
			$liu=$message->where('isopen','0')->count();
			if($res){
				if($liu!=0){
					echo '<script>parent.parent.document.getElementById("lizhili_liu").innerHTML="留',$liu,'"</script>';
				}else{
					echo '<script>parent.parent.document.getElementById("lizhili_liu").innerHTML="留"</script>';
				}
				return $this->success('修改成功',url('message/index',['st'=>1]));
			}else{
				$this->error('修改失败了');
			}
    	}
		$id=input('id',0);
		$data=$message->find($id);
        View::assign('data',$data);
       return View::fetch();
    }
}
